<%@page import="service.implement.ProjectDAO"%>
<%@page import="model.Timesheet"%>
<%@page import="model.Project"%>
<%@page import="service.implement.EmployeeDAO"%>
<%@page import="java.util.ArrayList"%>
<%@page import="model.Employee"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
	<%@ include file="Menu.jsp"%>
	<%
		String type = request.getParameter("typeSearch");
		if ("E".equals(type)) {
			ArrayList<Employee> list = (ArrayList<Employee>) request
					.getAttribute("ketquaTimkiem");
	%>
	<form id="search" action="doSearchEmployee" method="post">
		<table>
			<tr>
				<td><select name="typeSearch">
						<option selected value="E">Employee</option>
						<option value="P">Project</option>
						<option value="T">Time Sheet</option>

				</select></td>
				<td><input type="text" id="textinput" name="search" /></td>
				<td><input type="submit" class="submit1" value="Search" /></td>
			</tr>
		</table>
	</form>
	<form action="doEmployee" method="post">
		<div class="panel panel-default">
			<!-- Default panel contents -->
			<div class="panel-heading">Result search</div>

			<!-- Table -->
			<table class="table">
				<thead>
					<tr>
						<th>Id</th>
						<th>Name</th>
						<th>Username</th>
						<th>Email</th>
					</tr>
				</thead>
				<tbody>
					<%
						if (list.size() > 0)
								try {
									for (Employee e : list) {
					%>
					<tr>
						<td><%=e.getId()%></td>
						<td><%=e.getName()%></td>
						<td><%=e.getUsername()%></td>
						<td><%=e.getEmail()%></td>
						<td><a href="doEmployee?checkEmployee=<%=e.getId()%>">Edit</a></td>
					</tr>
					<%
						}
								} catch (Exception e) {
									e.printStackTrace();
								}
							else {
					%>
					Khong tim thay du lieu
					<%
						}
					%>
				</tbody>
			</table>
		</div>
		<%
			}
		%>
	</form>
	<%
		if ("P".equals(type)) {
			ArrayList<Project> list = (ArrayList<Project>) request
					.getAttribute("ketquaTimkiem");
	%>
	<form id="search" action="doSearch" method="post">
		<table>
			<tr>
				<td><select name="typeSearch">
						<option value="E">Employee</option>
						<option selected value="P">Project</option>
						<option value="T">Time Sheet</option>

				</select></td>
				<td><input type="text" id="textinput" name="search" /></td>
				<td><input type="submit" class="submit1" value="Search" /></td>
			</tr>
		</table>
	</form>
	<form>
		<div class="panel panel-default">
			<!-- Default panel contents -->
			<div class="panel-heading">Result search</div>

			<!-- Table -->
			<%
				if (list.size() > 0)
						try {
							for (Project p : list) {
			%>
			<table class="table">
				<thead>
					<tr>
						<th>Id</th>
						<th>NameProject</th>
						<th>Startdate</th>
						<th>Enddate</th>
					</tr>
				</thead>
				<tbody>
					<tr>
						<td><%=p.getId()%></td>
						<td><%=p.getNameProject()%></td>
						<td><%=p.getStartDate()%></td>
						<td><%=p.getEndDate()%></td>
						<td><a href="doProject?checkProject=<%=p.getId()%>">Edit</a></td>
					</tr>
					<%
						}
								} catch (Exception e) {
									e.printStackTrace();
								}
							else {
					%>
					Khong tim thay du lieu
					<%
						}
					%>
				</tbody>
			</table>
		</div>
		<%
			}
		%>
	</form>
	<%
		if ("T".equals(type)) {
			ArrayList<Timesheet> list = (ArrayList<Timesheet>) request
					.getAttribute("ketquaTimkiem");
			ArrayList<Employee> dsemp = new EmployeeDAO().getEmployee();
			ArrayList<Project> dspj = new ProjectDAO().getProject();
	%>
	<form id="search" action="doSearch" method="post">
		<table>
			<tr>
				<td><select name="typeSearch">
						<option value="E">Employee</option>
						<option selected value="P">Project</option>
						<option value="T">Time Sheet</option>

				</select></td>
				<td><input type="text" id="textinput" name="search" /></td>
				<td><input type="submit" class="submit1" value="Search" /></td>
			</tr>
		</table>
	</form>
	<form>
		<div class="panel panel-default">
			<!-- Default panel contents -->
			<div class="panel-heading">Result search</div>

			<!-- Table -->

			<%
				if (list.size() > 0)
						try {
							for (Timesheet t : list) {
								for (Employee e : dsemp) {
									for (Project p : dspj) {
										if (t.getEmployeeid() == e.getId()) {
											if (p.getId() == t.getProjectid()) {
			%>
			<table class="table">
				<thead>
					<tr>
						<th>Id</th>
						<th>Employee</th>
						<th>Project</th>
						<th>Date</th>
						<th>Duration</th>
						<th>Description</th>
						<th>Activity</th>
						<th>Overtime</th>
						<th>Location</th>
					</tr>
				</thead>
				<tbody>
					<tr>
						<td><%=t.getId()%></td>
						<td><%=e.getName()%></td>
						<td><%=p.getNameProject()%></td>
						<td><%=t.getDate()%></td>
						<td><%=t.getDuration()%></td>
						<td><%=t.getDescription()%></td>
						<td><%=t.getActivity()%></td>
						<td><%=t.getOvertime()%></td>
						<td><%=t.getLocation()%></td>
						<td><a href="doTimesheet?checkTimesheet=<%=t.getId()%>">Edit</a></td>
					</tr>
					<%
						}
												}
											}
										}
									}
								} catch (Exception e) {
									e.printStackTrace();
								}
							else {
					%>
					Khong tim thay du lieu
					<%
						}
					%>
				</tbody>
			</table>
		</div>
		<%
			}
		%>
	</form>
</body>
</html>